#wget http://s3.amazonaws.com/plink1-assets/plink_linux_x86_64_20200107.zip
config_path=$1

source ${config_path}/config.sh

################################################################## 
sample=Combine

## 1、combine vcf
ls ${gvcf_path} | grep -v tbi | grep recal | awk '{print gvcf"/"$0}' gvcf=${gvcf_path} > ${tmp_path}/sample_gvcf.list

bcftools merge --missing-to-ref --force-samples \
-l ${tmp_path}/sample_gvcf.list -Oz -o ${gvcf_path}/Combine.gvcf.gz

################################################################## 
## 合并1000Genome里报道的位点
vcftools --gzvcf ${gvcf_path}/Combine.gvcf.gz --positions ${ref}/1000GENOMES-phase_3_pos.txt \
--recode --out ${gvcf_path}/Combine_specific_position
bgzip -f ${gvcf_path}/Combine_specific_position.recode.vcf

################################################################## 
## 2、vcf->转格式
## 样本名带_,会导致plink无法实别
zcat ${gvcf_path}/${sample}_specific_position.recode.vcf.gz | sed 's/S_/S/g' | bgzip \
> ${gvcf_path}/${sample}_specific_position.recode.forPlink.vcf.gz

plink --vcf ${gvcf_path}/${sample}_specific_position.recode.forPlink.vcf.gz --make-bed --out ${plink_path}/${sample}

######计算亲属关系########
plink --bfile ${plink_path}/${sample} --maf 0.01 --genome --min 0 --out ${plink_path}/${sample}.genome

################################################################## 
## 整理数据
Rscript ${dna_preprocess_scripts}/Plink_IBD_v2.R \
--ibd_file ${plink_path}/Combine.genome.genome \
--out_path ${plink_path}